# import requests
# import time
#
# times = int(time.time() * 1000)
# url = (f'https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2'
#        f'&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2'
#        f'&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23'
#        f'&fid=f3&pn=2&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_={times}')
#
# headers = {
#     'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36',
#     'referer' : 'https://quote.eastmoney.com/center/gridlist.html',
#  }
#
# res = requests.get(url)
#
# datas = res.json()['data']['diff']
# for data in datas:
#     print(data['f14'])


# 异步请求
# import asyncio
# import aiohttp
# import time
# times = int(time.time() * 1000)
#
#
# async def fetch(session,url):
# 	async with session.get(url) as response:
# 		text = await response.json()['data']['diff']
# 		for data in text:
# 			print(data['f14'])
#
# async def main():
# 	urls = [(f'https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2'
# 		   f'&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2'
# 		    f'&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23'
# 		   f'&fid=f3&pn={i}&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_={times}') for i in range(1,2)]
# 	async with aiohttp.ClientSession() as session:
# 		await asyncio.gather(*[fetch(session,url) for url in urls])
# 		print("所有任务完成")
#
# asyncio.run(main())

# 多线程
# def main():
#     print('开始')
#
#
# if __name__ == '__main__':
#     main()
#


# 线程池 基于电脑的配置

import concurrent.futures
import requests
import time

times = int(time.time() * 1000)

def fetch(url):
	res = requests.get(url)
	text = res.json()['data']['diff']
	for data in text:
		print(data['f14'])
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor:
	urls = [(f'https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2'
		   f'&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2'
		    f'&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23'
		   f'&fid=f3&pn={i}&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_={times}') for i in range(1,5)]
	for url in urls:
		executor.submit(fetch,url)
		
		print(f"任务完成{url}")
		